﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Extensions;
using CustomProviders;

public partial class Controls_CategoryList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    private void RefreshSiteMap()
    {
        int categoryId = Request.QueryString["id"].ToInt32();  
        SqlSiteMapProvider smp = (SqlSiteMapProvider)SiteMap.Provider;
        SiteMapNode node = smp.FindSiteMapNodeFromKey(categoryId.ToString());
        smp.RebuildSiteMap();
    }
    protected void CategoryListView_ItemInserting(object sender, ListViewInsertEventArgs e)
    {
        int catId = Request.QueryString["id"].ToInt32();
        e.Values.Add("Parent", catId);
        e.Values["UrlId"] = "categoryById";
    }

    protected void CategoryListView_ItemDeleted(object sender, ListViewDeletedEventArgs e)
    {
        RefreshSiteMap();
    }
    protected void CategoryListView_ItemInserted(object sender, ListViewInsertedEventArgs e)
    {
        RefreshSiteMap();
    }
    protected void CategoryListView_ItemUpdated(object sender, ListViewUpdatedEventArgs e)
    {
        RefreshSiteMap();
    }
    protected void CategoryListView_DataBound(object sender, EventArgs e)
    {
        if (!Roles.IsUserInRole("Administrator"))
            if (CategoryListView.Items.Count == 0)
                CategoryListView.Visible = false;
            else
                CategoryListView.Visible = true;
    }
}
